package com.dimples.dd.system.mapper;

import com.dimples.dd.common.pojo.PageResult;
import com.dimples.dd.mybatis.core.query.LambdaQueryWrapperX;
import com.dimples.dd.system.model.entity.SystemFileConfigDO;
import com.dimples.dd.system.model.query.FileConfigPageQuery;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SystemFileConfigMapper extends com.dimples.dd.mybatis.core.mapper.BaseMapperX<SystemFileConfigDO> {

    /**
     * 根据主键查询主配置
     *
     * @return SystemFileConfigDO
     */
    default SystemFileConfigDO selectByMaster() {
        return selectOne(SystemFileConfigDO::getMaster, true);
    }

    default PageResult<SystemFileConfigDO> selectPage(FileConfigPageQuery pageQuery) {
        return selectPage(pageQuery, new LambdaQueryWrapperX<SystemFileConfigDO>()
                .likeIfPresent(SystemFileConfigDO::getName, pageQuery.getName())
                .eqIfPresent(SystemFileConfigDO::getStorage, pageQuery.getStorage())
                .betweenIfPresent(SystemFileConfigDO::getCreateTime, pageQuery.getCreateTime())
                .orderByDesc(SystemFileConfigDO::getId));
    }
}